<?php
/*********************************************************************************
 * Copyright (C) 2011-2013 X2Engine Inc. All Rights Reserved.
 *
 * X2Engine Inc.
 * P.O. Box 66752
 * Scotts Valley, California 95067 USA
 *
 * Company website: http://www.x2engine.com
 * Community and support website: http://www.x2community.com
 *
 * X2Engine Inc. grants you a perpetual, non-exclusive, non-transferable license
 * to install and use this Software for your internal business purposes.
 * You shall not modify, distribute, license or sublicense the Software.
 * Title, ownership, and all intellectual property rights in the Software belong
 * exclusively to X2Engine.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
 ********************************************************************************/

/* @edition:pro */

$this->actionMenu = $this->formatMenu(array(
	array('label' => Yii::t('charts', 'Grid Builder'), 'url' => array('gridReport')),
	array('label' => Yii::t('charts', 'Lead Performance'), 'url' => array('leadPerformance')),
	array('label' => Yii::t('charts', 'Saved Reports')),
	array('label' => Yii::t('charts', 'Deal Report'),'url'=>array('dealReport')),
	array('label' => Yii::t('workflow', 'Workflow'),'url'=>array('workflow')),
    array('label' => Yii::t('charts', 'User Activity'),'url'=>array('activityReport')),
    array('label' => Yii::t('services', 'Case Report'),'url'=>array('/services/servicesReport')),
));
?>
<div class='flush-grid-view'>
<?php

$this->widget('zii.widgets.grid.CGridView', array(
	'id' => 'reports-grid',
	'template'=>'<div class="page-title"><h2>'.Yii::t('charts','Saved Reports').'</h2><div class="title-bar">'.'{summary}</div></div>{items}{pager}',
	'dataProvider' => $dataProvider,
	'summaryText' => Yii::t('app','<b>{start}&ndash;{end}</b> of <b>{count}</b>')
		. '<div class="form no-border" style="display:inline;"> '
		. CHtml::dropDownList('resultsPerPage', Profile::getResultsPerPage(), Profile::getPossibleResultsPerPage(), array(
		    	'ajax' => array(
		    		'url' => $this->createUrl('/profile/setResultsPerPage'),
		    		'complete' => "function(response) { $.fn.yiiGridView.update('reports-grid', {data: {'id_page': 1}}) }",
		    		'data' => "js: {results: $(this).val()}",
		    	),
		    	'style' => 'margin: 0;',
		    ))
		. ' </div>',
	'baseScriptUrl'=>Yii::app()->request->baseUrl.'/themes/'.Yii::app()->theme->name.'/css/gridview',
	'columns' => array(
        array(
			'name' => Yii::t('charts','View Report'),
			'type' => 'raw',
			'value' => '$data->type=="grid"?CHtml::link(Yii::t("app","Link"),Yii::app()->controller->createUrl("gridReport",
                array(
                    "field1"=>$data->field1,
                    "field2"=>$data->field2,
                    "start"=>date("Y-m-d",$data->start),
                    "end"=>date("Y-m-d",$data->end),
                    "range"=>$data->dateRange,
                    "zero"=>$data->zero,
                    "cellType"=>$data->cellType,
                    "cellData"=>$data->cellData,
                    "id"=>$data->id,
                ))):CHtml::link(Yii::t("app","Link"),Yii::app()->controller->createUrl("dealReport",
                json_decode($data->parameters,true)))'
		),
        array(
			'name' => Yii::t('charts','Report Type'),
			'type' => 'raw',
			'value' => 'Yii::t("charts",ucfirst($data->type))',
		),
        array(
            'name' => Yii::t('charts','Model'),
            'type' => 'raw',
            'value' => 'Yii::t("app",isset($data->parameters)?ucfirst(current(json_decode($data->parameters,true))):"Contacts")'
        ),
		array(
			'name' => Yii::t('charts','Date Range'),
			'type' => 'raw',
			'value' => '$data->dateRange=="custom"?date("Y-m-d",$data->start)." to ".date("Y-m-d",$data->end):Yii::t("charts",Formatter::deCamelCase($data->dateRange))',
		),
		array(
			'name' => Yii::t('charts','Columns'),
			'type' => 'raw',
			'value' => '$data->type=="grid"?(Contacts::model()->getAttributeLabel($data->field2)):"-"'
		),
		array(
			'name' => Yii::t('charts','Rows'),
			'type' => 'raw',
			'value' => '$data->type=="grid"?(Contacts::model()->getAttributeLabel($data->field1)):"-"'
		),
		array(
			'name' => Yii::t('charts','Ignore Zeros?'),
			'type' => 'raw',
			'value' => '$data->type=="grid"?(Yii::t("app",$data->zero==1?"Yes":"No")):"-"'
		),
		array(
			'name' => Yii::t('charts','Data Type'),
			'type' => 'raw',
			'value' => '$data->type=="grid"?(Yii::t("charts",empty($data->cellType)?"Count":$data->cellType)):"-"'
		),
        array(
			'name' => Yii::t('charts','Cell Data Field'),
			'type' => 'raw',
			'value' => 'empty($data->cellType)?"-":$data->cellData'
		),
        array(
			'name' => Yii::t('charts','Create Date'),
			'type' => 'raw',
			'value' => 'Formatter::formatLongDate($data->createDate)'
		),
        array(
			'name' => Yii::t('charts','Created By'),
			'type' => 'raw',
			'value' => 'User::getUserLinks($data->createdBy)'
		),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete}'
        ),
	),
));

?>
</div>
